package com.itheima.controller;

import com.itheima.entity.*;
import com.itheima.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    DishService dishService;
    /*
    * 分页查询菜品
    *
    * */
    @GetMapping
    public Result page( Integer page , Integer PageSize){
        PageBean pageBean =  dishService.pageQuery(page,PageSize);
        //3.封装并返回查询结果
        return Result.success(pageBean);
    }
    /*
    * 添加
    * */
    @PostMapping
    public Result save(@RequestBody Dish dish) {
        //1. 接受请求参数: json格式请求参数(@RequestBody  + 实体类)

        //2. 调用业务层，来实现添加部门的功能
        dishService.saveDept(dish);

        //3. 封装处理结果数据
        return Result.success();//code=1,msg=success,data=null
    }
    /*
    * 根据id查询菜品信息
    * */
    @GetMapping("{id}")
    public Result queryOne(@PathVariable Integer id) {
        Emp emp = dishService.queryOne(id);

        return Result.success(emp);
    }
    /*
     * 更新
     * */
    @PutMapping()
    public Result update(@RequestBody Dish dish) {
        dishService.update(dish);

        return Result.success();
    }
    /*
     * 批量删除员工
     * */
    @DeleteMapping("/{ids}")
    public Result deleteBatch(@PathVariable List<Integer> ids) {
        //1. 接受请求参数：请求路径中的参数path，@PathVariable
        log.info("批量删除，ids={}", ids);
        //2. 调用业务层，实现批量删除员工
        dishService.delete(ids);
        //3.封装并返回处理结果
        return Result.success();
    }
    /*
    *
    *
    * */
   /* @PostMapping()
    public Result startOrStop(@PathVariable Integer status,Integer id){

        dishService.startOrStop(status,id);

        return Result.success();
    }*/
}
